public class Test2 {
    public static void main(String[] args) {
        StringBuilder stringBuilder = new StringBuilder("hello");
        StringBuilder stringBuilder1 = stringBuilder;

        //追加：即尾插 -> 字符 字符串 整型数字
        stringBuilder.append(' '); //hello

        stringBuilder.append("world"); //hello world

        stringBuilder.append(123);//hello world123

        System.out.println(stringBuilder);

        System.out.println(stringBuilder == stringBuilder1); //true

        System.out.println(stringBuilder.charAt(0));//获取0号位的字符

        System.out.println(stringBuilder.length());//获取字符数组的有效大小

        System.out.println(stringBuilder.capacity());//获取底层数组的总大小

        stringBuilder.setCharAt(0,'H');//设置任意位置的字符 Hello world123

        stringBuilder.insert(0,"hello world!!!");//helo world!!!Hello world123
        System.out.println(stringBuilder);

        System.out.println(stringBuilder.indexOf("hello"));//获取hello第一次出现的位置
        System.out.println(stringBuilder.lastIndexOf("helo"));//获取hello最后一次出现的位置

        System.out.println(stringBuilder.deleteCharAt(0));//删除首字符
        stringBuilder.delete(0,5);//删除[0,5)范围的字符
        String str = stringBuilder.substring(0,5);//截取[0,5)区间中的字符以String的方式返回

        System.out.println(str);
        stringBuilder.reverse();//z字符串逆置
        str = stringBuilder.toString();//将StringBuilder以String的方式返回
        System.out.println(str);
    }

}
